import React, { Component } from "react";
import PropTypes from 'prop-types'
import header from "./index.module.css";

export default class Header extends Component {

  static propTypes={
    add:PropTypes.func.isRequired
  }
  // 添加新的事件
  submit = (e) => {
    let { keyCode, target } = e;
    if (keyCode !== 13) return;
    if (target.value.trim()==='') {
      alert('输入不能为空')
      return
    }
    this.props.add(e.target.value);
    target.value='';
  };
  
  render() {
    return (
      <input
        onKeyUp={this.submit}
        type="text"
        className={header.input}
        placeholder="输入即将要做的事"
      />
    );
  }
}
